package com.oms.module.admin.controller.systemsettings;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.oms.common.ResponseDTO;
import com.oms.module.admin.constant.AdminResponseCodeConstant;
import com.oms.module.admin.domain.entity.AdminConfigEntity;
import com.oms.module.admin.domain.entity.BusinessConfigEntity;
import com.oms.module.admin.domain.entity.BuyerConfigEntity;
import com.oms.module.admin.domain.vo.ConfigParameterVO;
import com.oms.module.admin.service.AdminConfigService;
import com.oms.module.admin.service.BroadcastersConfigService;
import com.oms.module.admin.service.BusinessConfigService;
import com.oms.module.admin.service.BuyerConfigService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author zhanghailong QQ38592077
 * @Description TODO
 * @Date 2020/6/23 18:01
 */
@RestController
@RequestMapping("/system/administratorParameter")
@Api(value = "管理端系统配置")
public class SystemConfigController {
    @Autowired
    BuyerConfigService buyerConfigService;

    @Autowired
    BusinessConfigService businessConfigService;

    @Autowired
    AdminConfigService adminConfigService;

    @Autowired
    BroadcastersConfigService broadcastersConfigService;

    @PostMapping("/getBuyerConfig")
    public ResponseDTO<List<BuyerConfigEntity>> getBuyerConfigList(){
        List<BuyerConfigEntity> list = buyerConfigService.list();
        return ResponseDTO.succData(list);
    }

    @PostMapping("/modifyBuyerConfig")
    public ResponseDTO<List<BuyerConfigEntity>> modifyBuyerConfig(@RequestBody ConfigParameterVO configParameterVO){
        boolean update = buyerConfigService.update(Wrappers.<BuyerConfigEntity>lambdaUpdate().eq(BuyerConfigEntity::getId, configParameterVO.getId()).set(BuyerConfigEntity::getValue, configParameterVO.getValue()));
        if (update){
            return ResponseDTO.succMsg("修改成功");
        }
        return ResponseDTO.wrap(AdminResponseCodeConstant.MODIFY_BUYER_CONFIG_ERROR);
    }

    @PostMapping("/getBusinessConfig")
    public ResponseDTO<List<BusinessConfigEntity>> getBusinessConfig(){
        List<BusinessConfigEntity> list = businessConfigService.list();
        return ResponseDTO.succData(list);
    }

    @PostMapping("/modifyBusinessConfig")
    public ResponseDTO modifyBusinessConfig(@RequestBody ConfigParameterVO configParameterVO){
        boolean update = businessConfigService.update(Wrappers.<BusinessConfigEntity>lambdaUpdate().eq(BusinessConfigEntity::getId, configParameterVO.getId()).set(BusinessConfigEntity::getValue, configParameterVO.getValue()));
        if (update){
            return ResponseDTO.succMsg("修改成功");
        }
        return ResponseDTO.wrap(AdminResponseCodeConstant.MODIFY_BUSINESS_CONFIG_ERROR);
    }

    @PostMapping("/getAdminConfig")
    public ResponseDTO<List<AdminConfigEntity>> getAdminConfig(){
        List<AdminConfigEntity> list = adminConfigService.list();
        return ResponseDTO.succData(list);
    }

    @PostMapping("/modifyAdminConfig")
    public ResponseDTO modifyAdminConfig(@RequestBody ConfigParameterVO configParameterVO){
        boolean update = adminConfigService.update(Wrappers.<AdminConfigEntity>lambdaUpdate().eq(AdminConfigEntity::getId, configParameterVO.getId()).set(AdminConfigEntity::getValue, configParameterVO.getValue()));
        if (update){
            return ResponseDTO.succMsg("修改成功");
        }
        return ResponseDTO.wrap(AdminResponseCodeConstant.MODIFY_ADMIN_CONFIG_ERROR);
    }
}
